import axios from "axios";
import {Toast} from 'vant'

const instance = axios.create({
    baseURL: 'https://www.365msmk.com/api/app',
    headers: {
        'devicetype': 'H5',
    }
});

var toast = null
// "authorization": localStorage.getItem('adminToken') === null ? '' : "Bearer" + ' ' + localStorage.getItem('adminToken')
instance.interceptors.request.use(function (config) {
    //在发送之前做些什么
    if (localStorage.getItem('adminToken')) {
        config.headers['authorization'] = `Bearer ${localStorage.getItem('adminToken')}`
    }

    toast = Toast({
        className: 'wyss',
        duration: "toast",
        icon: "    https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1598627542509&di=e9b4675308b2158724938a6fbd6e4ebb&imgtype=0&src=http%3A%2F%2Fphoto.sjoneone.com%2Fuploads%2F2019%2F06%2F9cc3e09b8e586f3.gif",
    });

    return config;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});
instance.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    toast.clear();
    return response;
}, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});


export function myAxios(Type, urls, Promise) {
    switch (Type) {
        case "GET":
            return httpGit(urls, Promise);
        case "POST":
            return httpPost(urls, Promise)
        case "PUT":
            return httpPut(urls, Promise)
    }
}


function httpGit(urls, Promise) {
    return instance.get(urls, Promise)
}

function httpPost(urls, Promise) {
    return instance.post(urls, Promise)
}

function httpPut(urls, Promise) {
    return instance.put(urls, Promise)
}